package com.atguigu.guli.service.oss.controller.admin;


import com.atguigu.guli.service.base.result.R;
import com.atguigu.guli.service.oss.service.FileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@Api(tags = "阿里云文件管理")
@RestController

@RequestMapping("/admin/oss")
@Slf4j
public class FileController {
    @Autowired
    private FileService fileService;
    //上传文件
    @ApiOperation("文件上传")
    @PostMapping("/upload")
    /*
        swagger的ApiParm注解会导致传参出现空值的情况
     */
    public R upload(@ApiParam(value = "文件") MultipartFile file, String module) {
        String path = fileService.upload(file, module);
        return R.ok().data("path",path);
    }
    //文件上传2
    //@PostMapping("/upFile")
    //public Integer upFile(@ApiParam("年龄") Integer age){
    //    //String s = fileService.upload(file, module);
    //    //return R.ok().data("path",s);
    //    return age;
    //}
    //删除文件
    @ApiOperation("文件删除")
    @DeleteMapping("/delete")
    public R delete(String path,String module){
        fileService.deleteFile(path, module);
        return R.ok().message("文件删除成功");
    }
    //测试服务调用接口
    @ApiOperation(value = "测试")
    @GetMapping("/test")
    public R test() {
        log.info("oss test 被调用");
        return R.ok();
    }
}
